<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>

<!DOCTYPE html>
<html lang="zh-cn" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>云医通开放性接口平台</title>
<link rel="stylesheet" type="text/css" href="./css/mserver.css" />
<link rel="stylesheet" type="text/css" href="./css/calender.css" />
<link rel="stylesheet" type="text/css" href="./css/mserverother.css" />
<link rel="stylesheet" type="text/css" href="./css/tip-yellow.css" />
<link rel="stylesheet" type="text/css" href="./css/tip-darkgray.css" />
<link rel="stylesheet" type="text/css" href="./css/tableStyle.css" />
<script src="./js/jquery-1.8.0.min.js"></script>
<script src="./js/Common.js"></script>
<script src="./js/jquery.poshytip.min.js"></script>
</head>

<body>
	<div class="mserver imenu">
		<div class="header">
			<div class="inner cf" style="position: relative;">
				<a title="云医通开放性接口平台系统" href="Document.jsp">
					<h2>
						<span></span>
					</h2>
				</a>
				<ul>
					<li><a id="documentCenter" title="文档中心" target="_self">文档中心</a> <em style="display: block; margin-top: -1px; height: 8px;"></em></li>

					<li><a id="applicationCenter" href="javascript:void(0);" title="" target="_self">应用接入</a></li>
				</ul>
				<div class="ibtn">
					<a href="javascript:void(0);" title="登录" target="_self" class="btn_log"><span>登录</span></a> <a style="cursor: pointer;" title="设置个人信息" target="_self" class="btn_info" href="javascript:void(0);"><span>设置个人信息</span></a>
				</div>
				<div style="clear: right;"></div>
                <div class="ibtn" style="position: absolute; bottom: 0px; right: 0px;">
                    <input id="txt_Search" type="text" />
                    <a href="javascript:Public.SearchAPI();" title="查找" target="_self" class="btn_Search"><span>查找</span></a>
                </div>
			</div>
		</div>
		<input type="hidden" id="local_url" value="" />
		<div class="open_wrap">
			<div class="title_logo">
				<img src="./images/open_title.png" />
			</div>

			<div class="open_content">
				<div class="open_main clearfix">

					<div class="left">
						<div class="open3_menu_all">
							<h1>
								<a id="a_back" href="javascript:void(0);">返回</a>
							</h1>
							<ul class="open3_menu" style="display: block;">
							</ul>
						</div>
					</div>
					<!-- end of left -->

					<div class="right">
						<div class="api_list">
							<h1 id="api_define"></h1>
							<h3 id="api_name"></h3>
							<ul>
								<li><a href="#296">接口概述</a></li>
								<li><a href="#297">提交参数</a></li>
								<li><a href="#298">提交示例</a></li>
								<li><a href="#299">返回参数</a></li>
								<li><a href="#300">返回示例</a></li>
							</ul>
						</div>
						<ul class="detail_list">
							<%--接口概述--%>
							<li style="padding-bottom: 20px;">
								<div class="title">
									<h2>
										<a name="296">接口概述</a>
									</h2>
									<a class="show" style="cursor: pointer;">[隐藏]</a>
								</div>
								<div class="theme_content" style="text-indent: 24px;">
									<p>
										<label id="lb_description"></label>
									</p>
									<p>
										<label id="lb_requestdataformat"></label>
									</p>
									<p>
										<label id="lb_responsedataformat"></label>
									</p>
									<p>
										<label id="lb_httprequestmethod"></label>
									</p>
									<a class="more"></a>
								</div>
							</li>
							<%--提交参数--%>
							<li style="padding-bottom: 20px;">
								<div class="title">
									<h2>
										<a name="297">提交参数</a>
									</h2>
									<a class="show" style="cursor: pointer;">[隐藏]</a>
								</div>
								<div class="theme_content" style="text-indent: 24px;">
									<p>
										<strong>系统级输入参数：</strong>
									</p>
									<p>
										请参考<a href="Document.jsp?page=CallDescription.jsp#116">系统级输入参数</a>
									</p>
									<p>
										<strong>应用级输入参数：</strong>
									</p>
									<p>
									<div>
										<table id="tb_requestParam" width="100%" class="kindTable kindTable2" bordercolor="#ccdee8" border="1">
											<thead>
												<tr>
													<th><b><span style='color: black; font-family: 宋体; font-size: 9pt; mso-bidi-font-family: "Times New Roman"; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;'>变量名称</span></b></th>
													<th><b><span style='color: black; font-family: 宋体; font-size: 9pt; mso-bidi-font-family: "Times New Roman"; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;'>变量命名</span></b></th>
													<th><b><span style='color: black; font-family: 宋体; font-size: 9pt; mso-bidi-font-family: "Times New Roman"; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;'>变量类型</span></b></th>
													<th><b><span style='color: black; font-family: 宋体; font-size: 9pt; mso-bidi-font-family: "Times New Roman"; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;'>变量长度</span></b></th>
													<th><b><span style='color: black; font-family: 宋体; font-size: 9pt; mso-bidi-font-family: "Times New Roman"; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;'>是否必填</span></b></th>
													<th><b><span style='color: black; font-family: 宋体; font-size: 9pt; mso-bidi-font-family: "Times New Roman"; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;'>示例</span></b></th>
													<th><b><span style='color: black; font-family: 宋体; font-size: 9pt; mso-bidi-font-family: "Times New Roman"; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;'>说明</span></b></th>
												</tr>
											</thead>
											<tbody>
											</tbody>
										</table>
									</div>
									</p>
									<a class="more"></a>
								</div>
							</li>
							<%--提交示例--%>
							<li style="padding-bottom: 20px;">
								<div class="title">
									<h2>
										<a name="298">提交示例</a>
									</h2>
									<a class="show" style="cursor: pointer;">[隐藏]</a>
								</div>
								<div class="theme_content" style="text-indent: 24px;">
									<p>
										<strong>提交示例：</strong>
									</p>
									<p id="p_requestParamstruct"></p>
									<a class="more"></a>
								</div>
							</li>
							<%--返回参数--%>
							<li style="padding-bottom: 20px;">
								<div class="title">
									<h2>
										<a name="299">返回参数</a>
									</h2>
									<a class="show" style="cursor: pointer;">[隐藏]</a>
								</div>
								<div class="theme_content" style="text-indent: 24px;">
									<p>
										<strong>返回JSON格式说明：</strong>
									</p>
									<p>
									<div>
										<table id="tb_responseParam" width="100%" class="kindTable kindTable2" bordercolor="#ccdee8" border="1">
											<thead>
												<tr class="blueBg">
													<th><b><span style='color: black; font-family: 宋体; font-size: 9pt; mso-bidi-font-family: "Times New Roman"; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;'>变量名称</span></b></th>
													<th><b><span style='color: black; font-family: 宋体; font-size: 9pt; mso-bidi-font-family: "Times New Roman"; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;'>变量命名</span></b></th>
													<th><b><span style='color: black; font-family: 宋体; font-size: 9pt; mso-bidi-font-family: "Times New Roman"; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;'>变量类型</span></b></th>
													<th><b><span style='color: black; font-family: 宋体; font-size: 9pt; mso-bidi-font-family: "Times New Roman"; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;'>变量长度</span></b></th>
													<th><b><span style='color: black; font-family: 宋体; font-size: 9pt; mso-bidi-font-family: "Times New Roman"; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;'>是否必填</span></b></th>
													<th><b><span style='color: black; font-family: 宋体; font-size: 9pt; mso-bidi-font-family: "Times New Roman"; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;'>示例</span></b></th>
													<th><b><span style='color: black; font-family: 宋体; font-size: 9pt; mso-bidi-font-family: "Times New Roman"; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;'>说明</span></b></th>
												</tr>
											</thead>
											<tbody>
											</tbody>
										</table>
									</div>
									</p>
									<a class="more"></a>
								</div>
							</li>
							<%--返回示例--%>
							<li style="padding-bottom: 20px;">
								<div class="title">
									<h2>
										<a name="300">返回示例</a>
									</h2>
									<a class="show" style="cursor: pointer;">[隐藏]</a>
								</div>
								<div class="theme_content" style="text-indent: 24px;">
									<p>
										<strong>返回示例：</strong>
									</p>
									<p id="p_responseParamstruct"></p>
									<p>
										<br />
									</p>
									<a class="more"></a>
								</div>
							</li>

							<%--测试接口--%>
							<li style="padding-bottom: 20px;">
								<div class="title">
									<h2>
										<a name="301">测试接口</a>
									</h2>
								</div>
								<div class="theme_content" style="text-indent: 24px;">
									<p>
									</p>
									<p>
										<a id="btn_apitest" target="_blank" title="在线测试">
											<img src="images/demo.png" /></a>
									</p>
									<p>
										<br />
									</p>
									<a class="more"></a>
								</div>
							</li>


						</ul>
					</div>
					<!-- end of right -->

				</div>
				<!-- end of open_main -->
			</div>
			<!-- end of open_content -->
		</div>
		<!-- end of open_wrap -->

		<div class="footer" style="clear: both; margin-top: 600px;">
			<p>Copyright &copy; 广州云医科技有限公司 2015-2016, All Rights Reserved</p>
		</div>

		<a href="#" class="go_top"></a>
	</div>

	<script type="text/javascript">
        var apiId = '';
//        var apiclassid = '';

        var _variableType = {
            "1": "number",
            "2": "string",
            "3": "struct"
        };

        var _necessaryflag = {
            "1": "否",
            "2": "是"
        };

        // 获取接口列表信息
        function ApiList_Callback(ret) {
            if (ret) {
                var apilist = '';
                var _apiDefine = '';
                var _apiName = '';

                for (var i = 0; i < ret.length; i++) {
                    _apiDefine = ret[i].apiDefine;
                    _apiName = ret[i].apiName;

                    if (_apiDefine.length > 20)
                        _apiDefine = _apiDefine.substr(0, 20) + '...';
                    if (_apiName.length > 10)
                        _apiName = _apiName.substr(0, 10) + '...';

                    apilist += '<li><a name="' + ret[i].apiDefine + '<br/>' + ret[i].apiName + '" title="" id="apiId_' + ret[i].apiId + '" href="ApiDetails.jsp?apiClassId=' +  ret[i].apiClassId + '&apiId=' + ret[i].id + '"><p class="english">' + _apiDefine + '</p><p>' + _apiName + '</p></a></li>';
                }

                if ($.trim(apilist).length > 0) {
                    $('.open3_menu').append(apilist);
                    $('#apiId_' + apiId).addClass('now');

                    //poshytip 初始化
                    $(".open3_menu li").each(function (i) {
                        var a = $(".open3_menu li a");
                        var sid = $(a[i]).attr("id");
                        sid = "#" + sid;
                        $(sid).poshytip({
                            content: '',
                            className: 'tip-darkgray',
                            showOn: 'focus',
                            alignTo: 'target',
                            alignX: 'right',
                            alignY: 'bottom',
                            offsetX: 10,
                            showTimeout: 100
                        });
                        $(sid).poshytip('update', $(sid).attr("name"));
                        $(sid).hover(function () {
                            $(sid).poshytip("show");
                        }, function () {
                            $(sid).poshytip("hide");
                        });
                    });
                }
            }
        }

        // 获取接口信息
        function Api_Callback(ret) {
            if (ret && ret.length == 1) {
                if ($.trim(ret[0].apiClassId).length == 0 || apiClassId != ret[0].apiClassId) {
                    alert('参数错误');
                    window.location.href = "Document.jsp";
                    return;
                }
                else {
                    $('#a_back').text('返回' + ret[0].apiClassName);
                    $('#a_back').attr('href', 'API.jsp?apiClassId=' + apiClassId);
                }

                if ($.trim(ret[0].apiDefine).length > 0)
                    $('#api_define').text(ret[0].apiDefine);
                if ($.trim(ret[0].apiName).length > 0)
                    $('#api_name').text(ret[0].apiName);
                if ($.trim(ret[0].description).length > 0)
                    $('#lb_description').text('功能描述：' + ret[0].description);
                if ($.trim(ret[0].requestdataformat).length > 0)
                    $('#lb_requestdataformat').text('提交参数格式：' + ret[0].requestDataFormat);
                if ($.trim(ret[0].responsedataformat).length > 0)
                    $('#lb_responsedataformat').text('返回参数格式：' + ret[0].responseDataFormat);
                if ($.trim(ret[0].httprequestmethod).length > 0)
                    $('#lb_httprequestmethod').text('HTTP请求方式：' + ret[0].httpRequestMethod);
            }
        }

        // 获取接口对应的结构
        function Apistruct_Callback(ret) {
            var requestParamStructId = null;
            var responseParamStructId = null;
            if (ret && ret.length > 0) {
                var html = '';
                for (var i = 0; i < ret.length; i++) {
                    //根参数结构
               
                        switch (ret[i].apiStructType.toString()) {
                            case "1":
                                requestParamStructId = ret[i].structId;
                                break;
                            case "2":
                                responseParamStructId = ret[i].structId;
                                break;
                        }
                   
                }
                if ($.trim(requestParamStructId).length > 0) {
//                    Public.ajaxPost(window.parent.path + apis["getParamstruct"] + '?&structId=' + requestParamStructId, null, requestParamstruct_Callback, null);
                    Public.ajaxPost(window.parent.path + apis["getParametersByStruct"] + '?&structId=' + requestParamStructId, null, requestParam_Callback, null);
                }
                if ($.trim(responseParamStructId).length > 0) {
//                    Public.ajaxPost(window.parent.path + apis["getParamstruct"] + '?&structId=' + responseParamStructId, null, responseParamstruct_Callback, null);
                    Public.ajaxPost(window.parent.path + apis["getParametersByStruct"] + '?&structId=' + responseParamStructId, null, responseParam_Callback, null);
                }
            }
        }

        // 获取提交参数
        function requestParam_Callback(ret) {
            if (ret) {
                var html = '';
                var _example = '';
                var _parametername = '';

				//提交示例
				if ($.trim(ret.example).length > 0) {
					var jobj = JSON.parse(ret.example);
					var str_json = JSON.stringify(jobj, null, "\t");
					$('#p_requestParamstruct').text(str_json);
				}

				var paramdetails = ret.paramdetails;
				for(var j=0;j < paramdetails.length;j++){
					_example = $.trim(paramdetails[j].example).length == 0 ? '-' :paramdetails[j].example;
					_parameterName = paramdetails[j].paramdetailName;
					if (paramdetails[j].variableType.toString() == '3') {
						_parameterName = '<a href="StructRequest.jsp?apiClassId=' + apiClassId + '&apiId=' + apiId + '&structId=' + paramdetails[j].childStructId + '" title="点此查看结构" target="_blank"><strong>' + _parameterName + '</strong></a>';
					}

					html += '<tr><td><p>' + _parameterName + '</p></td><td><p>' + paramdetails[j].variableName + '</p></td><td><p>' + _variableType[paramdetails[j].variableType.toString()] +'</p></td><td><p>' + paramdetails[j].variableLength + '</p></td><td><p>' + _necessaryflag[paramdetails[j].necessaryFlag.toString()] + '</p></td><td><p>' + _example + '</p></td><td>' + paramdetails[j].description + '</td></tr>';
					}

                if ($.trim(html).length > 0) {
                    $('#tb_requestParam tbody').append(html);
                    $('#tb_requestParam tr:even').addClass('blueBg');
                    $('#tb_requestParam p').attr('align', 'center');
                }
            }
        }

        // 获取返回参数
        function responseParam_Callback(ret) {
			if (ret) {
				var html = '';
				var _example = '';
				var _parametername = '';
				var paramdetails = ret.paramdetails;
				//返回示例
				if ($.trim(ret.example).length > 0) {
					var jobj = JSON.parse(ret.example);
					var str_json = JSON.stringify(jobj, null, "\t");
					$('#p_responseParamstruct').text(str_json);
				}

				for(var j=0;j < paramdetails.length;j++){
					_example = $.trim(paramdetails[j].example).length == 0 ? '-' :paramdetails[j].example;
					_parameterName = paramdetails[j].paramdetailName;
					if (paramdetails[j].variableType.toString() == '3') {
						_parameterName = '<a href="StructRequest.jsp?apiClassId=' + apiClassId + '&apiId=' + apiId + '&structId=' + paramdetails[j].childStructId + '" title="点此查看结构" target="_blank"><strong>' + _parameterName + '</strong></a>';
					}

					html += '<tr><td><p>' + _parameterName + '</p></td><td><p>' + paramdetails[j].variableName + '</p></td><td><p>' + _variableType[paramdetails[j].variableType.toString()] +'</p></td><td><p>' + paramdetails[j].variableLength + '</p></td><td><p>' + _necessaryflag[paramdetails[j].necessaryFlag.toString()] + '</p></td><td><p>' + _example + '</p></td><td>' + paramdetails[j].description + '</td></tr>';
				}

				if ($.trim(html).length > 0) {
                    $('#tb_responseParam tbody').append(html);
                    $('#tb_responseParam tr:even').addClass('blueBg');
                    $('#tb_responseParam p').attr('align', 'center');
                }
            }
        }

        // 获取提交参数示例
//        function requestParamstruct_Callback(ret) {
//            if (ret && ret.length > 0) {
//                if ($.trim(ret[0].example).length > 0) {
//                    var jobj = JSON.parse(ret[0].example);
//                    var str_json = JSON.stringify(jobj, null, "\t");
//                    $('#p_requestParamstruct').text(str_json);
//                }
//            }
//        }

//        // 获取返回参数示例
//        function responseParamstruct_Callback(ret) {
//            if (ret && ret.length > 0) {
//                if ($.trim(ret[0].example).length > 0) {
//                    var jobj = JSON.parse(ret[0].example);
//                    var str_json = JSON.stringify(jobj, null, "\t");
//                    $('#p_responseParamstruct').text(str_json);
//                }
//            }
//        }

        function CheckUrl() {
            apiId = Public.GetUrlParam('apiId');
            apiClassId = Public.GetUrlParam('apiClassId');

            if ($.trim(apiId).length == 0 || $.trim(apiClassId).length == 0) {
                alert('参数错误');
                window.location.href = "Document.jsp";
            }
            
			$('#btn_apitest').attr('href', 'ApiTools.jsp?apiId=' + apiId);
        }

        $(function () {
			CheckUrl();
        	path = "<%=path%>/";
			Public.ajaxPost(window.parent.path + apis["getApi"] + "?apiClassId=" + apiClassId, null, ApiList_Callback, null);
			Public.ajaxPost(window.parent.path + apis["getApi"] + '?apiId=' + apiId, null, Api_Callback, null);
			Public.ajaxPost(window.parent.path + apis["getApistruct"] + '?apiStructType=0&apiId=' + apiId, null, Apistruct_Callback, null);

			$(".show").click(function() {
				Public.Fold(this);
			});
		});
	</script>
</body>
</html>